package com.hongning.railway.ui.main.cadremanager.itemviewmodel;

import android.databinding.ObservableField;
import android.databinding.ObservableInt;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;

import com.hongning.railway.R;
import com.hongning.railway.app.Constant;
import com.hongning.railway.entity.resbean.ResCadreBean;
import com.hongning.railway.ui.main.cadremanager.CadreGradeFragment;
import com.hongning.railway.ui.main.cadremanager.CadreManagerFragmentViewModel;
import com.hongning.railway.util.TimeUtils;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

/**
 * Author: zhangjing
 * DATA:2019-08-29 10:57
 * DESC:
 * email:zhangjingworkmol@163.com
 */
public class CadreManagerItemViewModel extends ItemViewModel<CadreManagerFragmentViewModel> {
    public ObservableField<String> name =new ObservableField<>();
    public ObservableField<String> time =new ObservableField<>();
    public ObservableField<String> statu =new ObservableField<>();
    public ObservableInt statuColor = new ObservableInt();
    ResCadreBean data;
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putParcelable(Constant.EXTRA_DATA,data);
            viewModel.startContainerActivity(CadreGradeFragment.class.getCanonicalName(),bundle);
        }
    });
    public CadreManagerItemViewModel(@NonNull CadreManagerFragmentViewModel viewModel, ResCadreBean resCadreBean) {
        super(viewModel);
        this.data=resCadreBean;
        name.set(resCadreBean.getCadretestname());
        if ("1".equals(resCadreBean.getHtmlstate())){
            statuColor.set(viewModel.getApplication().getResources().getColor(R.color.textc7));
        }else {
            statuColor.set(viewModel.getApplication().getResources().getColor(R.color.text99));
        }
        statu.set(resCadreBean.getStatuString());
        String timeinfo = "考核时间："+ TimeUtils.getFormatTime(resCadreBean.getCreateTime())+"-"+TimeUtils.getFormatTime(resCadreBean.getCadreteststoptime());
        time.set(timeinfo);
    }
}
